package com.open.server.api.system;

import com.open.system.dispatch.ILoginDispatch;
import com.open.common.model.Result;
import com.open.system.model.dto.LoginDto;
import com.open.system.model.dto.RegisterDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登陆验证
 *
 * @author dashu
 * @date 2025/2/1 23:57
 * @description
 */
@Slf4j
@RestController
public class LoginApi {

    @Autowired
    private ILoginDispatch loginDispatch;

    /**
     * 登录
     */
    @PostMapping("/login")
    public Result<?> login(@RequestBody LoginDto loginDto) {
        return Result.success(loginDispatch.login(loginDto));
    }

    /**
     * 查询用户信息
     */
    @GetMapping("/info")
    public Result<?> info() {
        return Result.success(loginDispatch.info());
    }

    /**
     * 退出
     */
    @PostMapping("/logout")
    public Result<?> logout() {
        return Result.success(loginDispatch.logout());
    }

    /**
     * 验证码获取接口
     */
    @GetMapping("/checkCode")
    public Result<?> checkCode() {
        return Result.success(loginDispatch.checkCode());
    }

    /**
     * 获取路由信息
     */
    @GetMapping("/getRouters")
    //@InterfaceExtend(title = "获取路由信息")
    public Result<?> getRouters(String menuName) {
        return Result.success(loginDispatch.getRouters(menuName));
    }

    /**
     * 注册接口
     */
    @PostMapping("/register")
    public Result<?> register(@RequestBody RegisterDto registerDto) {
        return Result.success(loginDispatch.register(registerDto));
    }
}
